.class public Lcom/philzhu/www/framework/impl/KeyboardHandler;
.super Ljava/lang/Object;
.source "KeyboardHandler.java"

# interfaces
.implements Landroid/view/View$OnKeyListener;


# instance fields
.field keyEventPool:Lcom/philzhu/www/framework/Pool;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lcom/philzhu/www/framework/Pool",
            "<",
            "Lcom/philzhu/www/framework/Input$KeyEvent;",
            ">;"
        }
    .end annotation
.end field

.field keyEvents:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/philzhu/www/framework/Input$KeyEvent;",
            ">;"
        }
    .end annotation
.end field

.field keyEventsBuffer:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/philzhu/www/framework/Input$KeyEvent;",
            ">;"
        }
    .end annotation
.end field

.field pressedKeys:[Z


# direct methods
.method public constructor <init>(Landroid/view/View;)V
    .locals 3
    .parameter "view"

    .prologue
    .line 19
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 14
    const/16 v1, 0x80

    new-array v1, v1, [Z

    iput-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->pressedKeys:[Z

    .line 16
    new-instance v1, Ljava/util/ArrayList;

    invoke-direct {v1}, Ljava/util/ArrayList;-><init>()V

    iput-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventsBuffer:Ljava/util/List;

    .line 17
    new-instance v1, Ljava/util/ArrayList;

    invoke-direct {v1}, Ljava/util/ArrayList;-><init>()V

    iput-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    .line 20
    new-instance v0, Lcom/philzhu/www/framework/impl/KeyboardHandler$1;

    invoke-direct {v0, p0}, Lcom/philzhu/www/framework/impl/KeyboardHandler$1;-><init>(Lcom/philzhu/www/framework/impl/KeyboardHandler;)V

    .line 26
    .local v0, factory:Lcom/philzhu/www/framework/Pool$PoolObjectFactory;,"Lcom/philzhu/www/framework/Pool$PoolObjectFactory<Lcom/philzhu/www/framework/Input$KeyEvent;>;"
    new-instance v1, Lcom/philzhu/www/framework/Pool;

    const/16 v2, 0x64

    invoke-direct {v1, v0, v2}, Lcom/philzhu/www/framework/Pool;-><init>(Lcom/philzhu/www/framework/Pool$PoolObjectFactory;I)V

    iput-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventPool:Lcom/philzhu/www/framework/Pool;

    .line 27
    invoke-virtual {p1, p0}, Landroid/view/View;->setOnKeyListener(Landroid/view/View$OnKeyListener;)V

    .line 28
    const/4 v1, 0x1

    invoke-virtual {p1, v1}, Landroid/view/View;->setFocusableInTouchMode(Z)V

    .line 29
    invoke-virtual {p1}, Landroid/view/View;->requestFocus()Z

    .line 30
    return-void
.end method


# virtual methods
.method public getKeyEvents()Ljava/util/List;
    .locals 4
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/List",
            "<",
            "Lcom/philzhu/www/framework/Input$KeyEvent;",
            ">;"
        }
    .end annotation

    .prologue
    .line 63
    monitor-enter p0

    .line 64
    :try_start_0
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->size()I

    move-result v1

    .line 65
    .local v1, len:I
    const/4 v0, 0x0

    .local v0, i:I
    :goto_0
    if-lt v0, v1, :cond_0

    .line 67
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->clear()V

    .line 68
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    iget-object v3, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventsBuffer:Ljava/util/List;

    invoke-interface {v2, v3}, Ljava/util/List;->addAll(Ljava/util/Collection;)Z

    .line 69
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventsBuffer:Ljava/util/List;

    invoke-interface {v2}, Ljava/util/List;->clear()V

    .line 70
    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    monitor-exit p0

    return-object v2

    .line 66
    :cond_0
    iget-object v3, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventPool:Lcom/philzhu/www/framework/Pool;

    iget-object v2, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEvents:Ljava/util/List;

    invoke-interface {v2, v0}, Ljava/util/List;->get(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/philzhu/www/framework/Input$KeyEvent;

    invoke-virtual {v3, v2}, Lcom/philzhu/www/framework/Pool;->free(Ljava/lang/Object;)V

    .line 65
    add-int/lit8 v0, v0, 0x1

    goto :goto_0

    .line 63
    .end local v0           #i:I
    .end local v1           #len:I
    :catchall_0
    move-exception v2

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v2
.end method

.method public isKeyPressed(I)Z
    .locals 1
    .parameter "keyCode"

    .prologue
    .line 57
    if-ltz p1, :cond_0

    const/16 v0, 0x7f

    if-le p1, v0, :cond_1

    .line 58
    :cond_0
    const/4 v0, 0x0

    .line 59
    :goto_0
    return v0

    :cond_1
    iget-object v0, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->pressedKeys:[Z

    aget-boolean v0, v0, p1

    goto :goto_0
.end method

.method public onKey(Landroid/view/View;ILandroid/view/KeyEvent;)Z
    .locals 6
    .parameter "v"
    .parameter "keyCode"
    .parameter "event"

    .prologue
    const/16 v5, 0x7f

    const/4 v4, 0x1

    const/4 v3, 0x0

    .line 34
    invoke-virtual {p3}, Landroid/view/KeyEvent;->getAction()I

    move-result v1

    const/4 v2, 0x2

    if-ne v1, v2, :cond_0

    move v1, v3

    .line 53
    :goto_0
    return v1

    .line 37
    :cond_0
    monitor-enter p0

    .line 38
    :try_start_0
    iget-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventPool:Lcom/philzhu/www/framework/Pool;

    invoke-virtual {v1}, Lcom/philzhu/www/framework/Pool;->newObject()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/philzhu/www/framework/Input$KeyEvent;

    .line 39
    .local v0, keyEvent:Lcom/philzhu/www/framework/Input$KeyEvent;
    iput p2, v0, Lcom/philzhu/www/framework/Input$KeyEvent;->keyCode:I

    .line 40
    invoke-virtual {p3}, Landroid/view/KeyEvent;->getUnicodeChar()I

    move-result v1

    int-to-char v1, v1

    iput-char v1, v0, Lcom/philzhu/www/framework/Input$KeyEvent;->keyChar:C

    .line 41
    invoke-virtual {p3}, Landroid/view/KeyEvent;->getAction()I

    move-result v1

    if-nez v1, :cond_1

    .line 42
    const/4 v1, 0x0

    iput v1, v0, Lcom/philzhu/www/framework/Input$KeyEvent;->type:I

    .line 43
    if-lez p2, :cond_1

    if-ge p2, v5, :cond_1

    .line 44
    iget-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->pressedKeys:[Z

    const/4 v2, 0x1

    aput-boolean v2, v1, p2

    .line 46
    :cond_1
    invoke-virtual {p3}, Landroid/view/KeyEvent;->getAction()I

    move-result v1

    if-ne v1, v4, :cond_2

    .line 47
    const/4 v1, 0x1

    iput v1, v0, Lcom/philzhu/www/framework/Input$KeyEvent;->type:I

    .line 48
    if-lez p2, :cond_2

    if-ge p2, v5, :cond_2

    .line 49
    iget-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->pressedKeys:[Z

    const/4 v2, 0x0

    aput-boolean v2, v1, p2

    .line 51
    :cond_2
    iget-object v1, p0, Lcom/philzhu/www/framework/impl/KeyboardHandler;->keyEventsBuffer:Ljava/util/List;

    invoke-interface {v1, v0}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 37
    monitor-exit p0

    move v1, v3

    .line 53
    goto :goto_0

    .line 37
    .end local v0           #keyEvent:Lcom/philzhu/www/framework/Input$KeyEvent;
    :catchall_0
    move-exception v1

    monitor-exit p0
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    throw v1
.end method
